package com.web.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.entity.Doctor;
import com.web.mapper.DoctorMapper;
import com.web.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public Boolean login(Doctor doctor) {
        Doctor doctor1 = doctorMapper.byPhone(doctor);
        if (doctor1 != null && doctor1.getPassword().equals(doctor.getPassword())) {
            return true;
        }
        return false;
    }

    @Override
    public Boolean byPhone(Doctor doctor) {
        Doctor doctor1 = this.doctorMapper.byPhone(doctor);
        if (doctor1 != null) {
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<Doctor> list(Integer page, Integer pageSize, Doctor doctor) {
        PageHelper.startPage(page, pageSize);
        PageInfo<Doctor> pageInfo = new PageInfo<>(doctorMapper.list(doctor));
        return pageInfo;
    }

    @Override
    public Doctor findById(Integer doctorId) {
        Doctor doctor = this.doctorMapper.findById(doctorId);
        return doctor;
    }

    @Override
    public void add(Doctor doctor) {
        doctor.setCreateTime(LocalDateTime.now());
        doctor.setUpdateTime(LocalDateTime.now());
        this.doctorMapper.add(doctor);
    }

    @Override
    public void update(Doctor doctor) {

        doctor.setUpdateTime(LocalDateTime.now());
        this.doctorMapper.update(doctor);
    }

    @Override
    public void delete(Integer doctorId) {
        this.doctorMapper.delete(doctorId);
    }
}
